﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using System.Linq.Expressions;

namespace MongoDB.Common
{
    public interface IMongoDBbase
    {
        /// <summary>
        /// 插入操作
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        /// <param name="t"></param>
        void Insert<T>(T t);

        /// <summary>
        /// 批量插入操作
        /// </summary>
        /// <param name="list"></param>
        void InsertBatch<T>(IList<T> list);

        /// <summary>
        /// 更新操作
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        void Update<T>(T t, ObjectId id);

        /// <summary>
        /// 更新操作
        /// </summary>
        /// <param name="t"></param>
        /// <param name="IDict">字典</param>
        void Update<T>(T t, IDictionary<string, object> IDict);
        /// <summary>
        /// 更新操作，更新多个文档
        /// </summary>
        /// <param name="t"></param>
        /// <param name="IDict"></param>
        void UpdateMulti<T>(T t, IDictionary<string, object> IDict);
        /// <summary>
        /// 更新或者插入
        /// </summary>
        /// <param name="t"></param>
        /// <param name="iDict"></param>
        void Upsert<T>(T t, IDictionary<string, object> iDict);

        /// <summary>
        /// 更新操作,需要_id属性，才能更新，否则为插入
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        void Save<T>(T t);
        /// <summary>
        ///读取单条记录
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        T Single<T>(Expression<Func<T, bool>> func);

        /// <summary>
        ///获取集合
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        IList<T> List<T>();

        /// <summary>
        ///获取集合
        /// </summary>
        /// <param name="func">条件委托函数</param>
        /// <returns></returns>
        IList<T> List<T>(Expression<Func<T, bool>> func);


        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="func"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        IList<T> List<T>(int pageIndex, int pageSize, out int pageCount, Expression<Func<T, bool>> func);

        /// <summary>
        /// 执行Javascript脚本
        /// </summary>
        /// <param name="javascriptcode"></param>
        BsonValue ExecuteJavaScript(string javascriptcode, params object[] args);
    }
}
